package com.nxu.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.nxu.dao.DoctorDao;

import com.nxu.entity.Booked;
import com.nxu.entity.Doctor;
import com.nxu.entity.Leave;
import com.nxu.entity.Report;
import com.nxu.entity.ViewReport;
import com.nxu.service.DoctorService;
import com.nxu.util.SqlSessionFactoryUtil;

public  class DoctorServiceImpl implements DoctorService{
	
	public int insertLeave(Leave leave) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		int count = doctorDao.insertLeave(leave);
		sqlSession.commit();
		sqlSession.close();
		return count;
		
	}

	@Override
	public List<Date> selectReservableDoctor(String dname) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		List<Date> list= doctorDao.selectReservableDoctor(dname);
		sqlSession.commit();
		sqlSession.close();
		return list;
	}

	

	@Override
	public List<Integer> selectBookedPid(String dname) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		List<Integer> list= doctorDao.selectBookedPid(dname);
		sqlSession.commit();
		sqlSession.close();
		return list;
	}

	@Override
	public List<ViewReport> selectReport(int vid) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		List<ViewReport> list2 = doctorDao.selectReport(vid);
		sqlSession.commit();
		sqlSession.close();
     	return list2;
	}

	@Override
	public int updateReport(String dtext,int vid) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		int count = doctorDao.updateReport(dtext,vid);
		sqlSession.commit();
		sqlSession.close();
		return count;
	}

	@Override
	public int insertDoctor(Doctor doctor) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		int count = doctorDao.insertDoctor(doctor);
		sqlSession.commit();
		sqlSession.close();
		return count;
	}

	@Override
	public String selectDoctor(String dname) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		String password = doctorDao.selectDoctor(dname);
		sqlSession.commit();
		sqlSession.close();
		return password;
	}

	@Override
	public List<Booked> selectBookedOnly(String dname) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		List list = doctorDao.selectBookedOnly(dname);
		sqlSession.commit();
		sqlSession.close();
		return list;
	}


	@Override
	public List<Report> selectReportVidDtext(String Dname) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		List<Report> list = doctorDao.selectReportVidDtext(Dname);
		sqlSession.commit();
		sqlSession.close();
		return list;
	}

	@Override
	public List<Doctor> selectShowDocter() {
		// TODO Auto-generated method stub
		SqlSession sqlSession = SqlSessionFactoryUtil.getsqlSessionFactory();
		DoctorDao doctorDao = sqlSession.getMapper(DoctorDao.class) ;
		List<Doctor> list = doctorDao.selectShowDoctor();
		sqlSession.commit();
		sqlSession.close();
		return list;
	}
}
